﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Jc.MicroDesigner.Exceptions
{
    /// <summary>
    /// Окно для вывода ошибок
    /// </summary>
    public partial class ExceptionDialog : Form
    {
        bool Mode = false;
        int MaximizeHeight = 290;

        private ExceptionDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Вывести сообщение об ошибке
        /// </summary>
        /// <param name="ex">Исключение</param>
        /// <param name="caption">Заголовок</param>
        /// <param name="message">Сообщение</param>
        public static void ShowException(Exception ex, string caption, string message)
        {
            ExceptionDialog dlg = new ExceptionDialog();
            dlg.MsgTextBox.Text = message;
            dlg.Text = caption;
            dlg.DetailsView.Text += "Сообщение: \n";
            dlg.DetailsView.Text += "\t" + ex.Message + "\n";
            dlg.DetailsView.Text += "Данные: \n";
            IDictionaryEnumerator enumer = ex.Data.GetEnumerator();
            while (enumer.MoveNext())
            {
                dlg.DetailsView.Text += enumer.Key.ToString() + " = " + enumer.Value.ToString() + "\n";
            }
            dlg.DetailsView.Text += "Стек:\n";
            dlg.DetailsView.Text += ex.StackTrace;

            System.Media.SystemSounds.Exclamation.Play();
            dlg.ShowDialog();
        }

        private void Details_Click(object sender, EventArgs e)
        {
            if (Mode)
            {
                MaximizeHeight = Height;
                Height = 135;
                Mode = false;
            }
            else
            {
                Height = MaximizeHeight;
                Mode = true;
            }
        }
    }
}